package com.hy.wsroom.util;

import com.hy.wsroom.entity.Client;
import lombok.Data;

import java.time.LocalDateTime;

@Data
public class ClientHolder {
    private static final ThreadLocal<Client> threadLocal = new ThreadLocal<>();
    public static void set(Client client) {
        threadLocal.set(client);
    }
    public static Client get() {
        return threadLocal.get();
    }

    public static String getClientId() {
        return threadLocal.get().getId();
    }
    public static void remove() {
        threadLocal.remove();
    }

    public static void updateLastActiveTime() {
        threadLocal.get().setLastActiveTime(LocalDateTime.now());
    }

}
